package webday03;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 演示重定向
 * 
 * @author luohui
 *
 */

public class Redirect extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//response.sendRedirect("http://baidu.com");
		
		//重定向如何传递参数
		
		//在第一个请求里面把参数取出来
		String parameter=request.getParameter("name");
		
		response.setStatus(HttpServletResponse.SC_FOUND);
		response.setHeader("Location", "Login.html");
		
		//把请求参数拼接到第二个路径的后面
		response.setHeader("Location", "request?name"+URLEncoder.encode(parameter,"utf-8"));
		
		
	}
}
